package com.fjut.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjut.model.vod.Course;
import com.fjut.result.Result;
import com.fjut.service.CourseService;
import com.fjut.vo.vod.CourseFormVo;
import com.fjut.vo.vod.CourseQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author DengTianxun
 * @since 2023-03-06
 */
@Api(tags = "课程接口")
@RestController
@RequestMapping("/fjut/vod/course")
//@CrossOrigin
public class CourseController {

    @Autowired
    private CourseService courseService;

    @ApiOperation("点播课程列表")
    @GetMapping("courseList/{page}/{limit}")
    public Result courseList(@PathVariable Long page, @PathVariable Long limit, CourseQueryVo courseQueryVo) {
        Page<Course> coursePage = new Page<>(page, limit);
        Map<String, Object> map = courseService.courseList(coursePage, courseQueryVo);
        return Result.success(map);
    }

    @ApiOperation("添加课程基本信息")
    @PostMapping("save")
    public Result save(@RequestBody CourseFormVo courseFormVo) {
        Long courseId = courseService.saveInfo(courseFormVo);
        return Result.success(courseId).message("添加课程成功");
    }

    @ApiOperation("删除课程信息")
    @DeleteMapping("deleteCourse/{id}")
    public Result deleteCourse(@PathVariable Long id) {
        return Result.success(courseService.deleteCourse(id)).message("删除成功！");
    }

    @ApiOperation("获取课程信息")
    @GetMapping("getCourseById/{id}")
    public Result getCourseById(@PathVariable Long id) {
        return Result.success(courseService.getCourseInfoById(id));
    }

    @ApiOperation("修改课程基本信息")
    @PostMapping("updateCourseInfo")
    public Result updateCourseInfo(@RequestBody CourseFormVo courseFormVo) {
        courseService.updateCourseInfo(courseFormVo);
        return Result.success(courseFormVo.getId()).message("修改课程成功");
    }

    @ApiOperation("获取已发布课程信息")
    @GetMapping("getCoursePublishVo/{id}")
    public Result getCoursePublishVo(@PathVariable Long id) {
        return Result.success(courseService.getCoursePublishVo(id));
    }

    @ApiOperation("课程最终发布")
    @PostMapping("publishCourse/{id}")
    public Result publishCourse(@PathVariable Long id) {
        return Result.success(courseService.publishCourse(id)).message("发布课程成功");
    }

    @ApiOperation("查询所有课程")
    @GetMapping("findAll")
    public Result findAll() {
        return Result.success(courseService.findList());
    }
}

